package saxion.speelveld.spaceengineer;

import saxion.speelveld.spaceengineer.database.AchievementDAO;
import saxion.speelveld.spaceengineer.model.Achievement;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class CustomAchievementPopup extends Activity
{

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.gained_achievement_toast);

		RelativeLayout rlmain = (RelativeLayout) findViewById(R.id.rlAchievementToast);
		rlmain.setOnClickListener(new ClickyListener());

		RelativeLayout rlContainer = (RelativeLayout) findViewById(R.id.rlAchievementToastContainer);
		rlContainer.setOnClickListener(new ClickyListener());

		Achievement achie = (Achievement) getIntent()
			.getSerializableExtra("saxion.speelveld.spaceengineer.achievement");

		TextView tvAchievementTitleAchievementToast = (TextView) findViewById(R.id.tvAchievementTitleAchievementToast);
		TextView tvAchievementExplanationAchievementToast = (TextView) findViewById(R.id.tvAchievementExplanationAchievementToast);

		tvAchievementTitleAchievementToast.setText(achie.getCaption());
		tvAchievementExplanationAchievementToast.setText(achie.getExplanation());

		AchievementDAO achievementDatasource = new AchievementDAO(getApplication());
		achievementDatasource.open();
		achievementDatasource.accomplishedAchievement(achie.getId());
		achievementDatasource.close();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.custom_achievement_popup, menu);
		return true;
	}

	private class ClickyListener implements OnClickListener
	{

		@Override
		public void onClick(View v)
		{
			finish();

		}

	}

}
